首页 \ 问答 \ 在图像上定位超链接(Positioning hyperlink over an image)

在图像上定位超链接(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
更新时间:2024-03-06 16:03

最满意答案

使用.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对象是一个包含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() 不会更改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) { ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。