gpt4 book ai didi

javascript - 添加到照片 slider 的链接

转载 作者:行者123 更新时间:2023-11-28 09:36:30 27 4
gpt4 key购买 nike

我的代码有问题。我对 JavaScript 几乎一无所知,所以任何帮助将不胜感激。

我想让这个淡入淡出 slider 中的横幅和照片(只有三张图片,但每张图片都有不同的链接)链接到网站上的页面。我不知道该怎么做。

这是该网站的链接,以便您可以看到我正在尝试做什么, http://www.buildings4babies.org

这是我当前的脚本。

(function($) {
$.fn.aToolTip = function(options) {

// setup default settings
var defaults = {
clickIt: true,
closeTipBtn: 'aToolTipCloseBtn',
fixed: false,
inSpeed: 200,
outSpeed: 0,
tipContent: '',
toolTipClass: 'aToolTip',
xOffset: 5,
yOffset: 5
},

// This makes it so the users custom options overrides the default ones
settings = $.extend({}, defaults, options);

return this.each(function() {
var obj = $(this);
// Decide weather to use a title attr as the tooltip content
if(obj.attr('title')){
// set the tooltip content/text to be the obj title attribute
var tipContent = obj.attr('title');
} else {
// if no title attribute set it to the tipContent option in settings
var tipContent = settings.tipContent;
}

// check if obj has a title attribute and if click feature is off
if(tipContent && !settings.clickIt){
// Activate on hover
obj.hover(function(el){
obj.attr({title: ''});
$('body').append("<div class='"+ settings.toolTipClass +"'><p class='aToolTipContent'>"+ tipContent +"</p></div>");
$('.' + settings.toolTipClass).css({
position: 'absolute',
display: 'none',
zIndex: '50000',
top: (obj.offset().top - $('.' + settings.toolTipClass).outerHeight() - settings.yOffset) + 'px',
left: (obj.offset().left + 1/2*(obj.outerWidth()) + settings.xOffset) + 'px'
})
.stop().fadeIn(settings.inSpeed);
},
function(){
// Fade out
$('.' + settings.toolTipClass).stop().fadeOut(settings.outSpeed, function(){$(this).remove();});
});
}

// Follow mouse if fixed is false and click is false
if(!settings.fixed && !settings.clickIt){
obj.mousemove(function(el){
$('.' + settings.toolTipClass).css({
top: (el.pageY - $('.' + settings.toolTipClass).outerHeight() - settings.yOffset),
left: (el.pageX + settings.xOffset)
})
});
}

// check if click feature is enabled
if(tipContent && settings.clickIt){
// Activate on click
obj.click(function(el){
obj.attr({title: ''});
$('body').append("<div class='"+ settings.toolTipClass +"'><p class='aToolTipContent'>"+ tipContent +"</p></div>");
$('.' + settings.toolTipClass).append("<a class='"+ settings.closeTipBtn +"' href='#' alt='close'>close</a>");
$('.' + settings.toolTipClass).css({
position: 'absolute',
display: 'none',
zIndex: '50000',
top: (obj.offset().top - $('.' + settings.toolTipClass).outerHeight() - settings.yOffset) + 'px',
left: (obj.offset().left + obj.outerWidth() + settings.xOffset) + 'px'
})
.fadeIn(settings.inSpeed);
// Click to close tooltip
$('.' + settings.closeTipBtn).click(function(){
$('.' + settings.toolTipClass).fadeOut(settings.outSpeed, function(){$(this).remove();});
return false;
});
return false;
});
}

}); // END: return this

// returns the jQuery object to allow for chainability.
return this;
};
})(jQuery);

最佳答案

我将向您介绍 jQuery 方法,因为您已经在使用它了。

您需要找出要用作链接元素的图片的元素 ID。在 html 中,它应该如下所示:"id="asdfasdf"

不幸的是,我在你的脚本中找不到插入图片的地方。我认为你没有找对地方,老实说,这个函数似乎显示 tooltips仅有的。

无论如何,一旦找到元素的 id,您就可以使用 jQuery 的 $('#idofyourelement') 选择它。如果它们没有 ID,您可以以其他方式选择它们。请参阅here进行介绍。

选择元素后,您可以使用wrap() -在其周围添加 html 链接的方法您可以安装 click - listner并调用打开新链接的函数:

function goToLink() {
window.location = "http://www.whereveryouwant.com"
}

$("#idofyourpicture").click(goToLink);

对您想要用作链接的每张图片执行此操作。

关于javascript - 添加到照片 slider 的链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12965694/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com