Jquery 这是一个优雅的方式,使元素淡入而滚动?
我的任务是在滚动时淡入元素,就像这样- 我是在从两个来源收集的jQuery代码的帮助下完成的:Jquery 这是一个优雅的方式,使元素淡入而滚动?,jquery,scroll,Jquery,Scroll,我的任务是在滚动时淡入元素,就像这样- 我是在从两个来源收集的jQuery代码的帮助下完成的: <script type="text/javascript"> $(document).ready( function() { tiles = $('.ajax_block_product').fadeTo(0,0); $(window).scroll(function(d,h) { tiles.each(function(i) { a = $(this)
<script type="text/javascript">
$(document).ready( function() {
tiles = $('.ajax_block_product').fadeTo(0,0);
$(window).scroll(function(d,h) {
tiles.each(function(i) {
a = $(this).offset().top + $(this).height();
b = $(window).scrollTop() + $(window).height();
if (a < b) $(this).fadeTo(500,1);
});
});
function inWindow(s){
var scrollTop = $(window).scrollTop();
var windowHeight = $(window).height();
var currentEls = $(s);
var result = [];
currentEls.each(function(){
var el = $(this);
var offset = el.offset();
if(scrollTop <= offset.top && (el.height() + offset.top) < (scrollTop + windowHeight))
result.push(this);
});
return $(result);
}
inWindow('.ajax_block_product').fadeTo(0,1);
});
</script>
$(文档).ready(函数(){
tiles=$('.ajax\u block\u product').fadeTo(0,0);
$(窗口)。滚动(功能(d,h){
瓷砖。每个(功能(i){
a=$(this.offset().top+$(this.height());
b=$(窗口).scrollTop()+$(窗口).height();
如果(a如果(scrollTop)有没有办法使这样的代码更简短,或者我的代码是解决这种问题的最佳方法?试试看