当鼠标悬停在标题上时突出显示邮箱
我的情况是,我的 WordPress 帖子显示在框中。当您将鼠标悬停在任何这些框上时,它将显示帖子的标题,并且其 RGBA 颜色会发生变化。目前正在工作,我对此感到满意。
现在您还可以在左侧看到它显示所有帖子标题。
现在我想要实现的是,当我将鼠标悬停在左侧的任何标题上时,它将突出显示该标题的特定帖子的框。突出显示意味着它将在框中显示帖子的 rgba 颜色和标题。
现在编写代码的方式是:
我使用一个循环来拉取帖子的所有标题并显示在左侧,并使用另一个循环来显示框(框内的帖子标题最初是隐藏的,但当鼠标悬停时会显示)在任何盒子上。)。
我使用 javascript 和 jquery 代码,并使用第 n 个子项和变量来查找悬停的标题,并尝试获取帖子标题 ID 并传递给数组,然后尝试获取该 ID 在数组内的位置,然后传递给第 n 个子项作为变量。但它不起作用,当我将鼠标悬停在左侧的任何标题上时,它会突出显示所有框,因为我再次使用循环来获取java脚本区域内的标题ID。
我有点迷路了,所以任何线索或提示都会是一个很大的帮助。你可以看到实时网站 查看该网站
,该特定页面中的整个代码是:
<div id="sidebar-documentary">
<ul id="sidebardocumentary-heading">
<li><a href="#">Documentaries Showreel 2011</a></li>
</ul>
<ul id="sidebardocumentary-title">
<?php query_posts('showposts=-1&cat=4'); $i = 1;?>
<?php if (have_posts()) : ?><?php while (have_posts()) : the_post(); ?>
<li>
<a href="<?php the_permalink() ?>" title="Permanent Link to <?php the_ID(); ?>" >
<?php the_title(); ?></a></li>
<?php endwhile;?>
<?php else : ?><h1>Uh oh...</h1>
<?php endif; ?>
<?php wp_reset_query(); ?>
</ul>
<ul id="sidebardocumentary-archive">
<li><a href="#">Archive</a></li>
</ul>
</div>
<div id="documentary-content">
<?php query_posts('showposts=-1&cat=4'); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div class="one">
<a href="#"><img src="<?php bloginfo('template_url'); ?>/images/featured-image.jpg"/></a>
<span class="details">
<div class="hover-content">
<a href="<?php the_permalink() ?>"><?php the_title();?></a>
呃哦...
</div> <!-- End documentary-content-->
// here is javascript code
<?php query_posts('showposts=-1&cat=4'); $i = 1;?>
<?php if (have_posts()) : ?><?php while (have_posts()) : the_post(); ?>
$j("#sidebardocumentary-title li a").mouseover(
function () {
<?php $key=0;
$postvalue[$a]=get_the_ID();
$i= $postvalue[$a];
$key= array_search($i, $postvalue);
?>;
var x = <?php echo $key; ?>;
x=x+1;
// 文档.write(x);
$j(this).stop().animate({backgroundColor:"#000000", color:"#FFFFFF"}, 0);
$j("#documentary-content .one:nth-child("+x+") .details").css({
"background-color": "rgba(65, 65, 65, 0.8)",
"width":"230px",
"height":"125px",
"margin-top":"-134px",
"overflow": "hidden",
"position": "relative",
"display": "block"
});
})
$j("#sidebardocumentary-title li a").mouseout(
function () {
$j(this).stop().animate({backgroundColor:"#FFFFFF", color:"#999999"}, 50);
$j("#documentary-content .one:nth-child(n) .details").css({
"display": "none"
});
});
<?php $a++; ?>
<?php endwhile; ?>
<?php else : ?><h1>Uh oh...</h1>
I'm in situation where I have wordpress posts showing in boxes. When you hover your mouse on any of these boxes it will display the title of the post and its rgba color gets change. Thats currently working and I'm happy with that.
Now you can also see in left side it display all the post titles.
Now What I want to achieve is, when I will hover mouse on any title in left side, it will highlight the box of the particular post of that title. Highlighting means it will display the rgba color and title of the post in the box.
Now the way the code was written is:
I used one loop to pull all the title of the post and display in left side and use another loop to display boxes (the post title inside the box is hidden initially, but it display when mouse hovers on any boxes.).
I used javascript and jquery code and I used nth child and variable to find which title was hovered and tried to get the post title ID and pass to array and then tried to get the position of that ID inside the array and then pass to nth child as a variable. But it did nt work, when I hover on any title in left side it hightlights all boxes, because I again used loop to get the title ID inside the java script area.
I'm kinda lost, so any clue or tips will be a great favour. you can see the live site on
see the site
and the whole code in that particular page is:
<div id="sidebar-documentary">
<ul id="sidebardocumentary-heading">
<li><a href="#">Documentaries Showreel 2011</a></li>
</ul>
<ul id="sidebardocumentary-title">
<?php query_posts('showposts=-1&cat=4'); $i = 1;?>
<?php if (have_posts()) : ?><?php while (have_posts()) : the_post(); ?>
<li>
<a href="<?php the_permalink() ?>" title="Permanent Link to <?php the_ID(); ?>" >
<?php the_title(); ?></a></li>
<?php endwhile;?>
<?php else : ?><h1>Uh oh...</h1>
<?php endif; ?>
<?php wp_reset_query(); ?>
</ul>
<ul id="sidebardocumentary-archive">
<li><a href="#">Archive</a></li>
</ul>
</div>
<div id="documentary-content">
<?php query_posts('showposts=-1&cat=4'); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div class="one">
<a href="#"><img src="<?php bloginfo('template_url'); ?>/images/featured-image.jpg"/></a>
<span class="details">
<div class="hover-content">
<a href="<?php the_permalink() ?>"><?php the_title();?></a>
Uh oh...
</div> <!-- End documentary-content-->
// here is javascript code
<?php query_posts('showposts=-1&cat=4'); $i = 1;?>
<?php if (have_posts()) : ?><?php while (have_posts()) : the_post(); ?>
$j("#sidebardocumentary-title li a").mouseover(
function () {
<?php $key=0;
$postvalue[$a]=get_the_ID();
$i= $postvalue[$a];
$key= array_search($i, $postvalue);
?>;
var x = <?php echo $key; ?>;
x=x+1;
// document.write(x);
$j(this).stop().animate({backgroundColor:"#000000", color:"#FFFFFF"}, 0);
$j("#documentary-content .one:nth-child("+x+") .details").css({
"background-color": "rgba(65, 65, 65, 0.8)",
"width":"230px",
"height":"125px",
"margin-top":"-134px",
"overflow": "hidden",
"position": "relative",
"display": "block"
});
})
$j("#sidebardocumentary-title li a").mouseout(
function () {
$j(this).stop().animate({backgroundColor:"#FFFFFF", color:"#999999"}, 50);
$j("#documentary-content .one:nth-child(n) .details").css({
"display": "none"
});
});
<?php $a++; ?>
<?php endwhile; ?>
<?php else : ?><h1>Uh oh...</h1>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
1)我认为你的源代码会产生类似的结果:
它将导致:
将鼠标悬停在任何侧栏标题上,将触发所有这些鼠标悬停功能。
2) 将鼠标悬停在侧栏上后,您的将显式分配一个样式,这会禁用
你的 .one:hover css 规则。
我建议:
有一个更清晰的结构来从菜单标题映射到 img。
例如,您可以执行以下操作:
和 js 代码:
希望它会有所帮助。
1) I think your sourcecode will produce something like:
It will result in:
Hovering on any side bar title, will trigger all these mouseover functions.
2) After hovering on the side bar, your <span> will be explicitly assigned with a style, which disables
your .one:hover css rules.
I would recommend:
Having a clearer structure to map from your menu title to img.
For instance, you can do something like:
And js code:
Hope it would help.