jQuery Simple Tips
Есть плагин на jQuery:
jQuery.fn.quicktip = function(options){
var defaults = {
speed: 500,
xOffset: 10,
yOffset: 10
};
var options = $.extend(defaults, options);
return this.each(function(){
var $this = jQuery(this)
//Pass the title to a variable and then remove it from DOM
if ($this.attr('title') != ''){
var tipTitle = ($this.attr('title'));
}else{
var tipTitle = ':)';
}
//Remove title attribute
$this.removeAttr('title');
$(this).hover(function(e){
$(this).css('cursor', 'pointer')
$("body").append("<div id='tooltip'>" + tipTitle + "</div>");
$("#tooltip")
.css("top", (e.pageY + defaults.xOffset) + "px")
.css("left", (e.pageX + defaults.yOffset) + "px")
.fadeIn(options.speed);
}, function() {
//Remove the tooltip from the DOM
$("#tooltip").remove();
});
$(this).mousemove(function(e) {
$("#tooltip")
.css("top", (e.pageY + defaults.xOffset) + "px")
.css("left", (e.pageX + defaults.yOffset) + "px");
});
});
};
$(document).ready(function(){
$('a, img').quicktip({
speed:700
});
});
Реализует тултипы. Вопрос, как сделать, чтобы реагировал ещё и на alt? |
jQuery.fn.quicktip = function(options){
var defaults = {
speed: 500,
xOffset: 10,
yOffset: 10
};
var options = $.extend(defaults, options);
return this.each(function(){
var $this = jQuery(this)
//Pass the title to a variable and then remove it from DOM
if (this.title||this.alt){
var tipTitle = this.title||this.alt;
}else{
var tipTitle = ':)';
}
//Remove title attribute
$this.removeAttr('title').removeAttr('alt');
$(this).hover(function(e){
$(this).css('cursor', 'pointer')
$("body").append("<div id='tooltip'>" + tipTitle + "</div>");
$("#tooltip")
.css("top", (e.pageY + defaults.xOffset) + "px")
.css("left", (e.pageX + defaults.yOffset) + "px")
.fadeIn(options.speed);
}, function() {
//Remove the tooltip from the DOM
$("#tooltip").remove();
});
$(this).mousemove(function(e) {
$("#tooltip")
.css("top", (e.pageY + defaults.xOffset) + "px")
.css("left", (e.pageX + defaults.yOffset) + "px");
});
});
};
$(document).ready(function(){
$('a, img').quicktip({
speed:700
});
});
|
А, так вот как надо было писать. Я что-то ступил. Спасибо большое!
|
А, забыл... Ещё вопросик.
Хотел убрать вот это:
else{
var tipTitle = ':)';
}
Чтобы, если title или alt отсутствуют, вообще ничего не показывалось. Так не помогло. |
| Часовой пояс GMT +3, время: 06:38. |