我希望在包含在 div 中的段落的最后一行上创建动画效果。其中有一些链接,因此看起来有点像这样:
<div id="wrapper"><p>Lorem ipsum dolor sit amet,
consectetur adipiscing elit. Integer eu dui et erat</p></div>
因此,无论页面加载时最后一个换行符发生在哪里,我都想选择带有跨度的最后一行以赋予其效果。
我不想使用 jQuery,即使我可能需要......
最佳答案
当您标记 jquery 时..这是一个 jquery 代码..但请务必首先包含 jquery
var parText = $('#wrapper p').text(); // get text of p
var parSplit = parText.split("\n"); // split text by \n
var lastLine = parSplit[parSplit.length-1]; // get last line
parText.replace(lastLine , ''); // replace last line with nothing
$('#wrapper p').append('<span>'+lastLine+'</span>'); // append the last line with `<span>lastline</span>` and give it a style you need
另一个DEMO具有下滑效果
关于javascript - 使用 Javascript 选择段落的最后一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33578974/