Yellow fade effect with JQuery

前端 未结 15 1771
萌比男神i
萌比男神i 2020-11-29 16:23

I would like to implement something similar to 37Signals\'s Yellow Fade effect.

I am using Jquery 1.3.2

The code

(function($) {
   $.fn.yell         


        
15条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-29 16:48

    I loved Sterling Nichols answer, since it was lightweight and didn't require a plugin. However, I discovered it didn't work with floating elements (i.e. such as when the element is "float:right"). So I re-wrote the code to display the highlight properly no matter how the element is positioned on the page:

    jQuery.fn.highlight = function () {
        $(this).each(function () {
            var el = $(this);
            $("
    ") .width(el.outerWidth()) .height(el.outerHeight()) .css({ "position": "absolute", "left": el.offset().left, "top": el.offset().top, "background-color": "#ffff99", "opacity": ".7", "z-index": "9999999" }).appendTo('body').fadeOut(1000).queue(function () { $(this).remove(); }); }); }

    Optional:
    Use the following code if you also want to match the border-radius of the element:

    jQuery.fn.highlight = function () {
        $(this).each(function () {
            var el = $(this);
            $("
    ") .width(el.outerWidth()) .height(el.outerHeight()) .css({ "position": "absolute", "left": el.offset().left, "top": el.offset().top, "background-color": "#ffff99", "opacity": ".7", "z-index": "9999999", "border-top-left-radius": parseInt(el.css("borderTopLeftRadius"), 10), "border-top-right-radius": parseInt(el.css("borderTopRightRadius"), 10), "border-bottom-left-radius": parseInt(el.css("borderBottomLeftRadius"), 10), "border-bottom-right-radius": parseInt(el.css("borderBottomRightRadius"), 10) }).appendTo('body').fadeOut(1000).queue(function () { $(this).remove(); }); }); }

提交回复
热议问题