在图像上定位超链接(Positioning hyperlink over an image)
我在链接图像时遇到问题。 我正在使用不透明度和悬停状态进行此链接,我设法让它工作,但结果不是我所期望的。 悬停不按我想要的方式工作。 我相信有更好的方法可以做到这一点,希望有人能够帮助我。 谢谢!
这是HTML代码:
<ul id="content-images"> <li><img class="show2" src="img/some_img.png" width="176" height="168"></li> <li><img class="show2" src="img/some_img2.png" width="176" height="168"></li> <li><img class="show2" src="img/some_img3.png" width="176" height="168"></li> </ul> <span class="show"><a href="#">Link1</a></span> <span class="show"><a href="#">Link2</a></span>
和CSS代码:
.show { opacity:0.8; position:relative; top:10px; left:10px; } .show:hover { opacity:1.0; } .show2 { left: 1px; opacity: 0.8; position: relative; top: -39px; } .show2:hover { opacity:1.0 }
I have a problem with positioning a link over an image. I am using the opacity and a hover state for this link and I managed to get it to work, but the outcome is not what I expected. The hover doesn't work the way I want. I believe there are better ways of doing this, hope someone will be able to help me. Thanks!
Here is HTML code:
<ul id="content-images"> <li><img class="show2" src="img/some_img.png" width="176" height="168"></li> <li><img class="show2" src="img/some_img2.png" width="176" height="168"></li> <li><img class="show2" src="img/some_img3.png" width="176" height="168"></li> </ul> <span class="show"><a href="#">Link1</a></span> <span class="show"><a href="#">Link2</a></span>
And CSS code:
.show { opacity:0.8; position:relative; top:10px; left:10px; } .show:hover { opacity:1.0; } .show2 { left: 1px; opacity: 0.8; position: relative; top: -39px; } .show2:hover { opacity:1.0 }
原文:https://stackoverflow.com/questions/18126264
最满意答案
使用
.each()
循环,以便在运行插件时引用该元素,如下所示:$('ul li').each(function() { $(this).qtip({ content: $(this).find('span.tooltip').text(), show: 'mouseover', hide: 'mouseout' }); });
Use a
.each()
loop so you can reference the element as you run the plugin on it, like this:$('ul li').each(function() { $(this).qtip({ content: $(this).find('span.tooltip').text(), show: 'mouseover', hide: 'mouseout' }); });
相关问答
更多-
是的,使用.get(index) 。 根据文件 : .get()方法可以访问每个jQuery对象下面的DOM节点。 Yes, use .get(index). According to the documentation: The .get() method grants access to the DOM nodes underlying each jQuery object.
-
jQuery对象和DOM元素(jQuery object and DOM element)[2022-03-14]
我想了解jQuery对象和DOM元素之间的关系 jQuery对象是一个包含DOM元素的类数组对象。 根据您使用的选择器,jQuery对象可以包含多个DOM元素。 还有什么方法可以对jQuery对象和DOM元素进行操作? 单个jQuery对象可以代表多个DOM元素吗? jQuery函数(一个完整的列表在网站上)对jQuery对象进行操作,而不是在DOM元素上操作。 您可以使用.get()访问jQuery函数内的DOM元素,或直接访问所需索引处的元素: $("selector")[0] // Accesses ... -
您需要使用回调函数来使用contextual this关键字。 $('#description img').attr('data-pic', function () { return $(this).attr('src'); } ); You need to use a callback function to use the contextual this keyword. $('#description img').attr('data-pic', function () { return $ ...
-
使用.each()循环,以便在运行插件时引用该元素,如下所示: $('ul li').each(function() { $(this).qtip({ content: $(this).find('span.tooltip').text(), show: 'mouseover', hide: 'mouseout' }); }); Use a .each() loop so you can reference the element as you run the plugin ...
-
您可以将$(“。field”)选择器更新为$(this)以选择字段和$(this).next()以在模糊和焦点功能中选择字段的标签。 只会选择所选字段和下一个标签,请参阅以下代码段: $(function() { $(".field").focus(function() { /* when field with or without value is focused, add these classes */ if ($(this).val().length || $(".fiel ...
-
我纠正了 $('.dropzone').click(function(){ var x,y; var Ans = $(this).attr('id'); $(this).animate({left:"100px"},"slow" ); $('#textid').val(Ans); }); var i=1; $('.item').click(function(){ var Ques =$(this).attr('id'); var lname = $(th ...
-
splice不是jQuery API的一部分,但您可以通过应用原型在jQuery集合上应用本机Array方法: Array.prototype.splice.call($myObject, 9, 1); // 0-index 您还可以使用pop删除最后一项: Array.prototype.pop.call($myObject); 这也应该给你一个正确的length属性。 splice is not part of the jQuery API, but you can apply native Arr ...
-
如果那些“元素”是实际的DOM元素(节点),那么你不能只使用$(e).data(...)吗? Ah, solved it already :) last version: This is somewhat simplified code: function setData(e,key,data){ if(typeof(e)==string){ e = $(e); } $(e).data(key,data); } solution Problem was, that I wanted to ke ...
-
获取元素的当前HTML(Get the current HTML of an element)[2022-03-21]
仅使用.html() 不会更改input的值。 它将继续使用初始值: 。 我建议使用.each()和.val() 。 JAVASCRIPT: $(document).ready(function(){ $('#b1').click(function(){ $('#stage input').each(function(){ $('#stage input').attr('value ... -
如果我理解正确,请使用以下内容: $('.search_txt:focus').parent().attr('data-id') 它将获得以类名.search_txt为焦点的输入,然后选择它的父项,并获取data-id的属性 例: $('.search_txt').autocomplete({ minLength: 1, source: function(request, response) { ...