How to show and hide comments and reference Buttons over the mouse in WordPress _ javascript skills

Source: Internet
Author: User
This article describes how to show and hide comments and reference Buttons over the mouse in WordPress. It is very practical to show and hide comments. For more information, see Display, hide, reply, and reference Buttons over the mouse
Ideas and principles
The principle is simple. If you have read one or two pages or even more pages of the Jquery manual,
You can understand the following principles. Otherwise, skip to the code implementation area.
The idea is simple,

Place the reply and reference buttons in the desired place, and set the CSS style to display: none;
Bind the hover action in Jquery to the area where you want to hover the cursor and display the button
Is it easy? If I write a blog before, it will definitely end,
Okay, now that you want to teach fish, continue .......

Code Implementation of special effects
Reply to and reference HTML code

The Code is as follows:

Reply | reference

Reply and reference CSS style settings

. Comment-act {display: none;} Jquery (Javascript) Code Part Note: li. comment is the region where each comment is located $ ('Li. comment '). hover (// Note 1 function () {$ (this ). find ('p. comment-act '). fadeIn (400);}, function () {$ (this ). find ('p. comment-act '). fadeOut (400 );});

Code enhancement and advanced extension of special effects
Jquery special effects often encounter such a situation,
Some extreme users will switch back and forth continuously in two areas with Hover animation effects (for testing ?),
Because we usually set a display time for the special effect display. Here we set the display time to 400 milliseconds,
Obviously, the user's mouse switches back and forth for about 100 milliseconds, or even less,
When you switch back and forth, an animation queue is usually generated, even if you do not move your mouse,
The special effects will be hidden and displayed based on the actions you have taken before the mouse until you have responded to the last mouse action,
Although I am not familiar with this situation, if we have many comments,
But is it easy for a visitor to slide his or her mouse over and over the content?
Is it annoying?
This will not only increase the client browser load, but also affect website efficiency and improve user experience.
Solving the problem is actually very simple. Use hover's callback function parameters to terminate the animation queue,

$ ('Li. comment '). hover (// Note 1 function () {$ (this ). find ('p. comment-act '). fadeIn (400);}, function () {$ (this ). find ('p. comment-act '). fadeOut (400, function () {$ (this ). stop (true );});});

Because when we move the mouse, we want to stop all animation displays,
Therefore, we can stop the animation queue in this area after moving the mouse out of the hidden reply and reference buttons.
According to the test, so far, MG12's blog has not dealt with this situation (lazy? No need ?).
You can use his blog for comparison!
Note 1: hover is a method that imitates the hover event (move the mouse over an object and remove it. This is a custom method,
It provides a "Stay in it" status for frequently used tasks.
When you move the cursor over a matching element, the specified first function is triggered. When you move the cursor out of this element, the specified second function is triggered.

Show and hide comments
This feature is available in many themes to reduce page space and improve user experience. I have reserved this feature for this topic, but it has never been changed because I am lazy. Recently, I am still lazy when I add a new version to my blog. I feel that I am so idle that I don't have to worry about it.

High finger positive
The JS Code is as follows:

Var cmtinfo = jQuery ('# cmtinfo'); if (cmtinfo. length> 0) {var hideinfo = cmtinfo. find ('# hide_author_info'); var showinfo = cmtinfo. find ('# show_author_info'); var authorinfo = jQuery ('# author_info'); authorinfo. hide (); showinfo. click (function () {jQuery (this ). fadeOut (function () {hideinfo. fadeIn () ;}); authorinfo. fadeIn () ;}); hideinfo. click (function () {jQuery (this ). fadeOut (function () {showinfo. fadeIn () ;}); authorinfo. fadeOut ();});} # cmtinfo is a new DIV of the visitor displayed by the visitor with information # hide_author_info, # show_author_info. One is a hidden button, and the other is a display button # author_info is # A Sub DIV of cmtinfo
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.