jQuery plugin for dynamic ellipsis effect (not used css), and stringWidth. (bonus)
IE 9 <= *
HTML source
<div style="width:100px;">ABCDEFGHIJKPQRSTUVWXYZ</div>
Script source
$("div").ellipsisWidth();
// |----100px---|
// ABCDEFGHIJ...
$("div").ellipsisWidth(50);
//or
$("div").ellipsisWidth({
width:50
});
// |-50px-|
// ABCD...
$("div").ellipsisWidth({
newText:"AAAAAAAAAAAAAAAAAAAA"
});
// AAAAAAAAAA...
$("div").ellipsisWidth({
replace:"***" // default "..."
});
// ABCDEFGHIJ***
$("div").ellipsisWidth({
replace:"<span>...</span>",
useHtml:true //default false
});
// ABCDEFGHIJ<span>...</span>
// (no escape..)
$("div").ellipsisWidth({
replace: "",
replaceWidth: 30
});
// |--70px--|-30px-|
// ABCDEFGHI
$("div").ellipsisWidth({
position:"middle" // "front"|"middle"|"after"|Number, default "after"
});
// ABCD...WXYZ
$("div").ellipsisWidth({
position:"front"
});
// ...RSTUVWXYZ
$("div").ellipsisWidth({
position:3
});
// ABC...UVWXYZ
$("div").ellipsisWidth({
position:-2
});
// ABCDEFG...YZ
<div style="width:100px;">C:/INNOMFT/webapp/boot/app/dispatchTransfer/test.zip</div>
<div style="width:100px;">C:/INNOMFT/webapp/boot/app/dispatchTransfer/test12345aaav22.zip</div>
$("div").ellipsisWidth({
path: true, //default false
position:"after"
});
// C:/IN.../test.zip
// /test1234...zip
path mode is firstly filename
<div style="width:100px;">C:\INNOMFT\webapp\boot\app\dispatchTransfer\test.zip</div>
$("div").ellipsisWidth({
path: true,
pathSeparator: "\\" //default "/"
});
// C:\IN...\test.zip
$("div").ellipsisWidth({
rerenderOnResize: true, //default false
});
rerender on browser resize.
$("div").ellipsisWidth({
width: 130,
replace:'<img src="/ellips.gif" width="20">',
useHtml:true,
replaceWidth: 20,
position: "middle"
});
$("<span>ABCDEFGHIJKPQRSTUVWXYZ</span>").ellipsisWidth(100);
// result: ???
it`s not working. render styles is not known on detached.
$("span").stringWidth("test");
// 15px, no render.
$("span").text("test").width();
// 15px, get after rendered
div{
width: 100px;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
used css. css is better... -_-*