gpt4 book ai didi

css - webkit 上的-moz-background-inline-policy

转载 作者:行者123 更新时间:2023-11-28 10:20:58 25 4
gpt4 key购买 nike

Webkit 中是否存在类似-moz-background-inline-policy 的东西?该属性基本上让您有机会指定如何为内联元素的每一行呈现背景。我在不同的浏览器上附加了相同元素的图像。

这是在 firefox 上的结果(使用 -moz-background-inline-policy: each-box;)

Firefox

这是在 Google Chrome 上的(我试过 -webkit-background-inline-policy,但它似乎不存在)

Google Chrome

更新

由于 Webkit 上没有后台策略属性,我正在尝试使用 jQuery 寻找不同的解决方案。我在每行文本后面添加了一个额外的跨度。没关系,除了文本没有正确测量这一事实。您可以在此处查看两个示例:

  1. 原方案(后台内联策略):http://jsfiddle.net/notme/mCnGy/5/
  2. 新解决方案(jQuery 跨度):http://jsfiddle.net/notme/my3br/1/

解决方案

//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<span/>') + 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();
};

//thanks @thirtydot
var fixIt = function() {
//remove previous .dummy
$('.dummy').remove();

$('div.node-title-text').each(function(index) {

var dummy = $(this).clone().removeClass().addClass('dummy').appendTo($(this).parent());
console.log(dummy);
$(dummy).wrapLines('<span><span>', '</span></span>');

var padding = 15;

dummy.css({
left: -padding,
right: -padding
}).find(' > span').css('padding-left', padding*2);

});
};

$(window).load(function(){
$(window).resize(fixIt).resize(); //trigger resize event onLoad
});

最佳答案

这行得通,但它可能会变得更有效率:

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

这里是后代的完整代码:

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<span/>') + 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('<span><span>', '</span></span>');
});
};
$(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:(与您的相同)

<div class="node-title">
<div class="node-title-text">
<a href="#">Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Sed suscipit fermentum leo eu scelerisque.</a>
</div>
</div>

关于css - webkit 上的-moz-background-inline-policy,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5529936/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com