简体   繁体   English

通过按钮悬停使元素改变颜色

[英]make elements change color with button hover

I seem to be struggling with this.我似乎正在为此而苦苦挣扎。 Im want to make other elements change with button hover.我想通过按钮悬停来改变其他元素。 what im trying to do is , when you hover on the "continue reading" button on the homepage , then for the title and post meta to change color.我想要做的是,当您将鼠标悬停在主页上的“继续阅读”按钮上时,标题和帖子元将更改颜色。

The site url is:网站网址是:

http://staging.conversationlab.com/lions_valley/ http://staging.conversationlab.com/lions_valley/

You probably just need to add some css:您可能只需要添加一些 css:

<style>
#buttonid:hover {
    background-color:#ff0000;
}
</style>

where the #buttonid is declared on your button: #buttonid 在按钮上声明的位置:

<button id="buttonid"> my button</button>

more info = better answer/s更多信息=更好的答案/秒

You can use the hover() method on the more links to trigger a function that applies or removes styling to their siblings like...您可以在 more 链接上使用hover()方法来触发一个函数,该函数将样式应用于或删除它们的兄弟姐妹,例如...

$(".more-link").hover(
  function() {
    $(this).addClass("your-class-with-styling");
    $(this).siblings(".post-meta").addClass("your-class-with-styling");
    $(this).siblings("h2").addClass("your-class-with-styling");
  },
  function() {
    $(this).removeClass("your-class-with-styling");
    $(this).siblings(".post-meta").removeClass("your-class-with-styling");
    $(this).siblings("h2").removeClass("your-class-with-styling");    
  }
);

I would probably add a class to the h2 to target, though, to make sure that it wouldn't conflict with any other h2s that MAY end up in those article sections at some point in the future.不过,我可能会向要定位的 h2 添加一个类,以确保它不会与可能在将来某个时候最终出现在这些文章部分中的任何其他 h2 冲突。

You can see here how to do it.你可以在这里看到如何做到这一点。 https://jsfiddle.net/5aybmjk7/ https://jsfiddle.net/5aybmjk7/

Basically I just added an ID / additional class to your code and then attached the relevant jquery that used mouseover and mouseout to highlight/unhighlight the title by adding or removing a class with CSS attached to it.基本上,我只是在您的代码中添加了一个 ID/附加类,然后附加了使用 mouseover 和 mouseout 通过添加或删除附加了 CSS 的类来突出显示/取消突出显示标题的相关 jquery。

$('#here').mouseover(function () {
    $(".highlightMe").addClass('colored');
});

$('#here').mouseout(function () {
    $(".highlightMe").removeClass('colored');
});
jQuery('.et_pb_posts article').find('.more-link').on('hover', function() {
    jQuery(this).find('.post-meta a').addClass('YOUR_CLASS')
});

Try that试试看

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

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