0
夥計!我有一些使用rtl轉換的代碼,但這裏的字母有錯誤的轉換(旋轉)。不知道如何完全解釋它。這很難閱讀。我希望你能理解。有人可以幫我嗎?字母轉換
function wrap(element) {
var text = element.getAttribute('data-original');
if (!text) {
text = element.textContent.trim();
element.setAttribute('data-original', text);
}
var words = text.split(/\s+/);
var result = '',
line = '',
reverseLine = false;
element.innerHTML = 'a';
var height = element.offsetHeight;
for (var i = 0; i < words.length; i++) {
var candidate = line + ' ' + words[i];
element.innerHTML = result + candidate;
if (element.offsetHeight > height) {
height = element.offsetHeight;
result += '<div>' + line + '</div>';
line = words[i];
} else {
line = candidate;
}
}
if (line) result += '<div>' + line + '</div>';
element.innerHTML = result;
}
function wrapAll() {
console.time('wrapAll()');
[].forEach.call(document.querySelectorAll('.text-inverse'), wrap);
console.timeEnd('wrapAll()');
}
wrapAll();
window.onresize = wrapAll;
.text-inverse div:nth-child(2n) {
direction: rtl;
unicode-bidi: bidi-override;
white-space: nowrap;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<div class="courses">
<h1>Header</h1>
<time class="date" datetime="2016-11-08"></time>
<p class="course text-inverse">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec at cursus nisi. Morbi in quam eget quam aliquet laoreet vitae ac metus. Suspendisse nulla risus, faucibus vel lacus ac, sagittis accumsan nunc. Ut eleifend elit vitae commodo posuere. Donectincidunt, nulla vel ullamcorper tempor, nisl libero pretium tellus, eget luctus sem tellus in mi. Curabitur hendrerit urna in facilisis posuere. Ut ornare quis nibh et tincidunt. Mauris id orci a nisi lacinia eleifend sed id lectus.</p>
</div>
你幾乎得到它,但我需要這個字母,不是的話 – Blacksky
我看你改變你的答案。感謝您的提示,但它仍然是用於文字而不是用於信件...也許更多的想法? – Blacksky
對不起,我重新編輯了答案,因爲我認爲這個解決方案會更容易。我用字母替換前一個。 –