【发布时间】:2026-01-13 02:25:02
【问题描述】:
我的网站是一个音乐网站,每页有 24 个单曲播放器。问题是播放器没有在新加载的页面上加载。
我在我的网站上使用无限滚动,我无法获得回调来处理我的无限滚动代码,所以根据我的研究,.live 是下一步要采取的措施。
不幸的是,我不知道如何在我的代码中实现 .live。我不确定它是否适用于这种情况。
有没有人有任何相关的例子,甚至可以帮助解决这种情况。
音频播放器代码如下:
//Audio jquery
$(function(){
$(".audio").mb_miniPlayer({
width:210,
height:34,
inLine:false,
onEnd:playNext
});
var $audios = $('.audio');
function playNext(idx) {
var actualPlayer=$audios.eq(idx),
$filteredAtoms = $container.data('isotope').$filteredAtoms,
isotopeItemParent = actualPlayer.parents('.isotope-item'),
isoIndex = $filteredAtoms.index( isotopeItemParent[0] ),
nextIndex = ( isoIndex + 1 ) % $filteredAtoms.length;
$filteredAtoms.eq( nextIndex ).find('.audio').mb_miniPlayer_play();
};
});
不确定是否需要,但这里是无限滚动代码:
//Inifinite Scroll
var $container = $('#container');
$container.isotope({
itemSelector : '.square'
});
$container.infinitescroll({
navSelector : '#page_nav', // selector for the paged navigation
nextSelector : '#page_nav a', // selector for the NEXT link (to page 2)
itemSelector : '.square', // selector for all items you'll retrieve
loading: {
finishedMsg: 'No more pages to load.',
img: 'http://i.imgur.com/qkKy8.gif'
}
},
// call Isotope as a callback
function( newElements ) {
var $newElements = $(newElements);
// add hover events for new items
bindSquareEvents( $newElements );
setTimeout(function() {
$container.isotope('insert', $newElements );
}, 1000);
});
Div 示例:
<div class="square pop">
<!-- DJ Picture -->
<img src="Pictures/adrianlux.jpg" class="img1" />
<div class="boxtop">
<span class="genre">Pop</span>
</div>
<div class="box">
<a class="close" href="#close">×</a>
<!-- DJ Name -->
<h1>Adrian Lux</h1>
<!-- Song Title -->
<h2>Alive (Extended Mix)</h2>
<!--Song Description(179 characters with spaces)-->
<h4>Although this is not truly a pop song, I don't think it can be classified as anything else. The transition from spoken-word lyrics to rising vocals is wonderful as is the drop that follows.</h4>
<div class="buttons">
<!--Song file info-->
<div class="player">
<a id="m75" class="audio {skin:'#010101',showVolumeLevel:false,showTime:false,showRew:false,ogg:'MP3/Adrian Lux feat. The Good Natured - Alive (Extended Mix).ogg'}" href="MP3/Adrian Lux feat. The Good Natured - Alive (Extended Mix).mp3"></a></div>
<!--Download Link-->
<div class="download">
<a href="MP3/Adrian Lux feat. The Good Natured - Alive (Extended Mix).mp3" title='Right Click and Save Link As'>
<img src="img/dlicon.png"/></a>
</div>
</div>
</div>
</div>
【问题讨论】:
-
不要使用
.live(),使用.on()。如果.on()不可用(例如,当您使用 jQuery .delegate() 是可行的方法(它更有效,其语法鼓励更合理的用例)。总结一下:1)使用.on(),2)如果没有.on(),使用.delegate(),3)如果没有.delegate(),则使用.live()。 -
好的。我也在查看.on,但找不到太多关于如何在这种情况下实现它的信息。不过,我还没有研究过 .delegate 。我现在就这样做。
-
该评论在这种情况下根本没有帮助,任何形式的委派都无法帮助他。
-
@user1063192:它们非常相似,除了
.live()已被弃用(或多或少)以支持.delegate()和.delegate()已被弃用以支持.on()。如果你有.on(),那么使用它,给出selector参数(参见the documentation)。但要获得帮助,您可能需要更详细地解释您的网站是如何工作的。
标签: javascript jquery html ajax infinite-scroll