我正在尝试制作一些元素以便在形成某些东西时进行缩放,我正在使用Jquery路点(http://imakewebthings.com/jquery-waypoints/shortcuts/sticky-elements/)并且我尝试优化代码以运行几个元素它可以正常工作Firefox,Chrome和Safari但无法让它在臭名昭着的Internet Explorer上运行。 HTML是这样的:
<div style="height: 300px;">TODO write content</div>
<div class="container">
<img src="images/image1.png"/>
<img src="images/image2.png"/>
<img src="images/image3.png"/>
<img src="images/image4.png"/>
</div>
<!--This are just for adding some space for the scrolling-->
<div style="height: 300px;">TODO write content</div>
<div style="height: 300px;">TODO write content</div>
<div style="height: 300px;">TODO write content</div>
<div style="height: 300px;">END</div>
CSS:
.my-sticky-element.stuck {
position:fixed;
top:0;
}
自定义JS:
$(document).ready(function() {
$('.container').find('img').each(function() {
imgnum+=1
var $this=$(this);
var stickyclass="my-sticky-element";
$this.addClass("my-sticky-element");
console.log(stickyclass);
$this.waypoint('sticky', {
offset: 30 // Apply "stuck" when element 30px from top
});
});