Reputation: 691
Here's my first jquery script:
<!DOCTYPE html>
<html>
<head>
<title>Sliding test</title>
<style>
html {
height: 100%;
padding: 0;
margin: 0;
}
body{
text-align: center;
background: url('bg.png');
height: 100%;
margin: 0;
padding: 0;
box-shadow: 0 0 900px 35px rgba(0, 0, 0, 0.5) inset;
}
#global_wrap {
width: 1000px;
margin: 30px auto 0;
}
.container {
/*background: pink;*/
height: 240px;
width: 290px;
overflow: hidden;
border-radius: 5px 5px 5px 5px;
border: 3px solid #EAEAEA;
display: inline-block;
}
.slide_wrapper {
height: 500px;
width:290px;
margin-left: 0px;
padding-left: 0px;
text-align: left;
background: white;
margin-top: 0;
}
li {
color: grey;
list-style: none outside none;
}
a {
color: inherit;
text-decoration: none;
}
img {
display: block;
}
h3 {
background: none repeat scroll 0 0 #252525;
color: white;
font-family: sans-serif;
margin: 0;
padding-bottom: 12px;
padding-top: 12px;
text-align: center;
width: 290px;
}
</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<div id="global_wrap">
<div class="container">
<div class="slide_wrapper">
<a href="javascript:;">
<img src="visuel1.jpg" width="290" height="193">
<h3>Category 1</h3>
</a>
<ul>
<li><a href="#">link</a></li>
<li><a href="#">link</a></li>
<li><a href="#">link</a></li>
<li><a href="#">link</a></li>
<li><a href="#">link</a></li>
</ul>
</div>
</div>
<div class="container">
<div class="slide_wrapper">
<a href="javascript:;" >
<img src="visuel2.png" width="290" height="193">
<h3>Category 2</h3>
</a>
<ul>
<li><a href="#">link</a></li>
<li><a href="#">link</a></li>
<li><a href="#">link</a></li>
<li><a href="#">link</a></li>
<li><a href="#">link</a></li>
</ul>
</div>
</div>
<div class="container">
<div class="slide_wrapper">
<a href="javascript:;">
<img src="visuel3.jpg" width="290" height="193">
<h3>Category 3</h3>
</a>
<ul>
<li><a href="#">link</a></li>
<li><a href="#">link</a></li>
<li><a href="#">link</a></li>
<li><a href="#">link</a></li>
<li><a href="#">link</a></li>
</ul>
</div>
</div>
</div>
<script>
//wrapper_click=false;
$(".slide_wrapper a").click(function(){
if($(this).hasClass('open'))
{
// wrapper_click = false;
$(this).parent().animate({'margin-top': '0px'}, 'slow');
$(this).removeClass('open');
}
else
{
//wrapper_click = true;
$(this).parent().animate({'margin-top': '-193px'}, 'slow');
$(this).addClass('open');
}
});
</script>
</body>
</html>
I dont't know why, but it works fine on jsfiddle: http://jsfiddle.net/svmK5/
It works fine on all browsers, excepted chrome, I don't understand why... I think I’ve made some errors in my code, which makes it laggy
Does someone haves an idea about what is wrong in script?
Upvotes: 0
Views: 1757
Reputation: 1
This works fine in Chrome 26.0.1410
img{ image-rendering: -webkit-optimize-contrast; }
Upvotes: 0
Reputation: 691
I found what made the script laggy, it was due to this CSS property:
html {
height: 100%;
}
i don't know why this made my script laggy, but when i remove it, my script works perfectly
thank you all for your help, and particulary joel harkes for your very usefull help!
Upvotes: 2
Reputation: 11661
it works fine in chrome here, you could choose to use toggle class for less coding:
// toggleClass( class, [duration] )
$(".slide_wrapper a").click(function () {
$(this).parent().toggleClass('open','slow');
});
css:
.open {
'margin-top': '-193px'
}
also all links inside the slide_wrapper
will execute the on click even, i would suggest:
<a class="toggler" href="javascript:;">
$(".toggler").click...
this fiddle might help: http://jsfiddle.net/svmK5/8/
to fix the layout bug i used:
.slide_wrapper {
float: left
}
Upvotes: 1