1
我使用簡單Text Rotator和其夢幻般的,我的,我與它唯一的問題是單擊事件我還沒有與它的工作:jQuery的 - 簡單的文本肩與點擊事件
$(function() {
$('a[href*=#]:not([href=#])').click(function() {
if(!$(this).hasClass('carousel-control')){
if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top - topSize
}, 2000);
return false;
}
}
}
});
});
當我點擊鏈接在文本旋轉器它不滾動,只是去的ID部分(#link-1 &#link-2)(link-3.php和link-4.php工作正常,因爲他們去另一個頁面)
<h1 class="sliding-text">
<span class="rotate">
<a href="#link-1">Link 1</a>,
<a href="#link-2">Link 2</a>,
<a href="link-3.php">Link 3</a>,
<a href="link-4.php">Link 4</a>
</span>
</h1>
$(".sliding-text .rotate").textrotator({
animation: "fade",
speed: 1000
});
這裏是該庫的jQuery代碼:
!function ($) {
var defaults = {
animation: "fade",
separator: ",",
speed: 2000
};
$.fx.step.textShadowBlur = function (fx) {
$(fx.elem).prop('textShadowBlur', fx.now).css({ textShadow: '0 0 ' + Math.floor(fx.now) + 'px black' });
};
$.fn.textrotator = function (options) {
var settings = $.extend({}, defaults, options);
return this.each(function() {
var el = $(this)
var array = [];
$.each(el.html().split(settings.separator), function (key, value) {
array.push(value);
});
el.html(array[0]);
// animation option
var rotate = function() {
switch (settings.animation) {
case 'fade':
el.fadeOut(500, function() {
index = $.inArray(el.html(), array)
if ((index + 1) == array.length) index = -1
el.text(array[index + 1]).fadeIn(settings.speed);
});
break;
}
};
setInterval(rotate, 8000);
});
}
}(window.jQuery);
如何讓我的點擊事件與我的文字轉子工作
作品,這是非常感謝! – user979331