-moz-background-inline-policy on webkit

后端 未结 2 1645
日久生厌
日久生厌 2021-01-20 02:15

Does something like -moz-background-inline-policy exist in Webkit? This property basically gives you the opportunity to specify how should background render for

2条回答
  •  清歌不尽
    2021-01-20 02:48

    This works, but it could probably be made more efficient:

    http://jsfiddle.net/thirtydot/UGBXD/3/

    Here's the complete code for posterity:

    JS:

    //thanks @Peter Bailey - http://stackoverflow.com/questions/2456442/how-can-i-highlight-the-line-of-text-that-is-closest-to-the-mouse/2456582#2456582
    jQuery.fn.wrapLines = function(openTag, closeTag) {
        var dummy = this.clone().css({
            top: -9999,
            left: -9999,
            position: 'absolute',
            width: this.width()
        }).appendTo(this.parent()),
            text = dummy.text().match(/\S+\s+/g);
    
        var words = text.length,
            lastTopOffset = 0,
            lines = [],
            lineText = '';
    
        for (var i = 0; i < words; ++i) {
            dummy.html(
            text.slice(0, i).join('') + text[i].replace(/(\S)/, '$1') + text.slice(i + 1).join(''));
    
            var topOffset = jQuery('span', dummy).offset().top;
    
            if (topOffset !== lastTopOffset && i != 0) {
                lines.push(lineText);
                lineText = text[i];
            } else {
                lineText += text[i];
            }
    
            lastTopOffset = topOffset;
        }
        lines.push(lineText);
    
        this.html(openTag + lines.join(closeTag + openTag) + closeTag);
        dummy.remove();
    };
    
    var fixIt = function() {
        $('.dummy').remove();
    
        $('div.node-title-text').each(function(index) {
            //remove previous .dummy
            var dummy = $(this).clone().removeClass().addClass('dummy').appendTo($(this).parent());
            $(dummy).wrapLines('', '');
        });
    };
    $(window).resize(fixIt).resize(); //trigger resize event onLoad
    

    CSS:

    .node-title {
        position: relative;
        margin-bottom: 16px
    }
    .node-title-text {
        position: relative;
        z-index: 2
    }
    .dummy {
        position: absolute;
        top: 0; left: 0;
        z-index: 1
    }
    .dummy > span {
        background: url('http://i.stack.imgur.com/HPofR.png') top left no-repeat,
            url('http://i.stack.imgur.com/C8ImH.png') top right no-repeat,
            url('http://i.stack.imgur.com/9is9r.png') top center repeat-x;
    }
    .dummy > span > span {
        visibility: hidden
    }
    

    HTML: (same as yours)

    
    

提交回复
热议问题