我开始在我的网站上应用引导程序。 我需要更改以下脚本以使用bootstrap carousel
$(function(){
// Set starting slide to 1
var startSlide = 1;
// Get slide number if it exists
if (window.location.hash) {
alert('hash'+window.location.hash);
startSlide = window.location.hash.replace('#','');
alert('startslide'+startSlide);
}
// Initialize Slides
$('#slides2').slides({
preload: true,
preloadImage: 'img/loading.gif',
generatePagination: true,
play: 0,
pause: 2500,
hoverPause: true,
currentClass: 'current',
// Get the starting slide
start: {$startNumb},
animationComplete: function(current){
// Set the slide number as a hash
window.location.hash = '#' + current;
alert('windows hash'+window.location.hash);
alert('current'+current);
$('#activeSlideIndex').val(current);
$('#popLightbox div.rating a').attr('rel', imageIdArray[current-1] +';media');
$('#popLightbox a.voteNegative').html('<img src="{$liveSite}/templates/{$theme}/desktop_images/images/unlike.png" align="absmiddle"><b class="sprite"> </b> ' + voteCountArray[current-1][0]);
$('#popLightbox a.votePlus').html('<img src="{$liveSite}/templates/{$theme}/desktop_images/images/approve.png" align="absmiddle"><b class="sprite"> </b> ' + voteCountArray[current-1][1]);
}
});
我尝试过类似的东西,但它没有用。
我不知道current
变量在哪里获得它的价值以及window.location.hash
如何工作
$(function(){
// Set starting slide to 1
var startSlide = 1;
// Get slide number if it exists
if (window.location.hash) {
startSlide = window.location.hash.replace('#','');
}
$('#myCarousel').bind('slide',function(current){
window.location.hash = '#' + current;
$('#activeSlideIndex').val(current);
$('#popLightbox div.rating a').attr('rel', imageIdArray[current-1] +';media');
$('#popLightbox a.voteNegative').html('<img src="{$liveSite}/templates/{$theme}/desktop_images/images/unlike.png" align="absmiddle"><b class="sprite"> </b> ' + voteCountArray[current-1][0]);
$('#popLightbox a.votePlus').html('<img src="{$liveSite}/templates/{$theme}/desktop_images/images/approve.png" align="absmiddle"><b class="sprite"> </b> ' + voteCountArray[current-1][1]);
});
});
答案 0 :(得分:0)
找到了一个解决方案。这个获得了旋转木马的当前索引
$('#myCarousel').bind('slid',function(e){
var current = $(".active", e.target).index()+1;
$('#activeSlideIndex').val(current);
$('#popLightbox div.rating a').attr('rel', imageIdArray[current-1] +';media');
$('#popLightbox a.voteNegative').html('<img src="{$liveSite}/templates/{$theme}/desktop_images/images/unlike.png" align="absmiddle"><b class="sprite"> </b> ' + voteCountArray[current-1][0]);
$('#popLightbox a.votePlus').html('<img src="{$liveSite}/templates/{$theme}/desktop_images/images/approve.png" align="absmiddle"><b class="sprite"> </b> ' + voteCountArray[current-1][1]);
});