简体   繁体   English

如何在悬停时让此菜单保持在图像的右上角? - CSS,jQuery

[英]How do I get this menu to stay top right of the image on hover? - CSS, jQuery

You can see the implementation here . 你可以在这里看到实现

When you hover over any of the two big images, you see a little 'menu' set of icons appear. 当您将鼠标悬停在两个大图像中的任意一个上时,会看到一组“菜单”图标出现。 They are absolutely positioned right now. 他们现在绝对定位。

I want them to function like a menu - so when you hover over the image, they appear to the top right of each of the images, ie when you hover over the left image, it appears in the top right corner of the left image, and when you hover over the right image, it does the same. 我希望它们像菜单一样运作 - 所以当你将鼠标悬停在图像上时,它们会显示在每个图像的右上角,即当你将鼠标悬停在左图像上时,它会出现在左图像的右上角,当你将鼠标悬停在右边的图像上时,它会做同样的事情。

Also note that the images are on a carousel, so when you click next, the menu should disappear and you should get the menu on the next image that shows up too. 另请注意,图像位于旋转木马上,因此当您单击下一步时,菜单应该消失,您应该在下一个显示的图像上显示菜单。 Also why are those black dots appearing, is it because the images are list items? 也是为什么出现这些黑点,是因为图像是列表项?

How do I get rid of them? 我怎么摆脱他们?

Also, when you hover over the menu, it shouldn't flicker like it does now - and should allow me to be able to customize it like a menu (ie when they hover over each of the images, I can do an image swap to make it feel like a menu (even after one of the icons/buttons has been pressed). 此外,当您将鼠标悬停在菜单上时,它不应该像现在一样闪烁 - 并且应该允许我像菜单一样自定义它(即当它们悬停在每个图像上时,我可以进行图像交换到使它感觉像一个菜单(即使按下其中一个图标/按钮后)。

Here is the requisite code....HTML: 这是必需的代码.... HTML:

<div id="slider-code">
    <a class="buttons prev" href="#"></a>
    <div class="viewport">
        <ul class="overview">           
            <li><img src="images/red-stripe.jpg" /></li>
            <li><img src="images/red-stripe-bw.jpg" /></li>
            <li><img src="images/red-stripe-red.jpg" /></li>            
            <li><img src="images/red-stripe-dark.jpg" /></li>
            <li><img src="images/red-stripe.jpg" /></li>
            <li><img src="images/red-stripe-red.jpg" /></li>
            <li><img src="images/red-stripe-dark.jpg" /></li>           
        </ul>

        <div id="edit-image-nav">
            <ul>
                <li><img src="images/comment-icon.png" /></li>
                <li><img src="images/paint-icon.png" /></li>
                <li><img src="images/delete-icon.png" /></li>
            </ul>
        </div>

    </div>
    <a class="buttons next" href="#"></a>
</div>

CSS: CSS:

#edit-image-nav {
    display: none;
}

#edit-image-nav ul {
    display: inline;    
    margin: 20px 0 auto; /* top, right, bottom, left */
    position: absolute; 
    z-index: 200;   
}

#edit-image-nav ul li {
    float: left;
}

JS JS

$(document).ready(function() {
    $("#slider-code .viewport .overview img")
        .hover(function() {
            $("#edit-image-nav").css({ 'display' : 'inline' });
        }, function() {
            $("#edit-image-nav").css({ 'display' : 'none' });
    });

});

Thanks. 谢谢。

check into jquery ui position... http://jqueryui.com/demos/position/ 检查jquery ui位置... http://jqueryui.com/demos/position/

very handy and it works pretty good. 非常方便,它的效果非常好。

To the css you should add the top and right values so it can place them where you want them. 对于css,您应该添加topright值,以便将它们放置在您想要的位置。

#edit-image-nav ul {
    display: inline;    
    margin: 20px 0 auto; /* top, right, bottom, left */
    position: absolute; 
    z-index: 200;   
}

Also, you may want to look into using mouseenter and mouseleave instead of hover (which behind the scenes uses mouseover and mouseout ) 此外,你可能要考虑使用mouseentermouseleave ,而不是hover (其幕后使用mouseovermouseout

$('.element').mouseenter(function() {
    $("#edit-image-nav").css({ 'display' : 'inline' });
}).mouseleave(function(){
    $("#edit-image-nav").css({ 'display' : 'none' });
});

There is a reason to use mouseenter vs mouseout - it has to do with nested elements. 使用mouseenter和mouseout是有原因的 - 它与嵌套元素有关。 You can see that here . 你可以看到在这里

You can see the demos directly on mouseover and mouseenter . 您可以直接在mouseovermouseenter上查看演示。

If you want to show menu on each image try this: 如果要在每个图像上显示菜单,请尝试以下操作:

CSS: CSS:


 ul.overview li {position: relative;}
#edit-image-nav {positon: absolute; display: none; right: 5px;}

JS: JS:
 $(document).ready(function() { var imageNav=$("#edit-image-nav").remove(); $("#slider-code .viewport .overview img").mouseenter(function(event) { imageNav.insertAfter(this).css({ 'display' : 'block' }); } ).mouseleave( function(event) { imageNav.css({ 'display' : 'none' }).remove(); }); }); 

Something like this might work for you: Example 这样的东西可能对你有用: 例子

JavaScript used: 使用的JavaScript:

$('.overview li').mouseenter(function() {
    $(this).append($('#tool'));
    $('#tool').css('display', 'block');
}).mouseleave(function() {
    $('#tool').css('display', 'none');
});

HTML used: 使用的HTML:

<ul class="overview" >            
    <li><img src="http://fiwishop.com/feedback/images/red-stripe.jpg" ></li>
    <li><img src="http://fiwishop.com/feedback/images/red-stripe-bw.jpg" ></li>
    <li><img src="http://fiwishop.com/feedback/images/red-stripe-red.jpg" ></li>                
</ul>

<div style="clear:both"></div>
<div id="tool">[ ] [_] [X]</div>

CSS used: 使用的CSS:

.overview li{
    width:200px;
    height:135px;
    background-color:#666;
    float:left;
    margin:10px;
}
.overview li img{
    width:200px;
    position:absolute;
}
#tool{
    width:75px;
    background-color:#eee;
    display:none;
    position:relative;
    left:120px;
    top:5px
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM