AvocadoAmber/AvocadoEdition_Light/js/viewimageresize.js

93 lines
1.9 KiB
JavaScript
Raw Normal View History

(function ($) {
$.fn.viewimageresize = function (selector) {
var cfg = {
selector: "img"
};
if (typeof selector == "object") {
cfg = $.extend(cfg, selector);
} else {
if (selector) {
cfg = $.extend({ selector: selector });
}
}
2022-09-17 20:50:50 +09:00
var $img = this.find(cfg.selector);
var $this = this;
2022-09-17 20:50:50 +09:00
$img.removeAttr("height")
.css("height", "");
2022-09-17 20:50:50 +09:00
function image_resize() {
var width = $this.width();
2022-09-17 20:50:50 +09:00
$img.each(function () {
if ($(this).data("width") == undefined)
$(this).data("width", $(this).width());
2022-09-17 20:50:50 +09:00
if ($(this).data("width") > width) {
$(this).removeAttr("width")
.removeAttr("height")
.css("width", "")
.css("height", "");
2022-09-17 20:50:50 +09:00
if ($(this).data("width") > width) {
$(this).css("width", "100%");
}
2022-09-17 20:50:50 +09:00
} else {
$(this).attr("width", $(this).data("width"));
2022-09-17 20:50:50 +09:00
}
});
}
$(window).on("load", function () {
image_resize();
});
$(window).on("resize", function () {
image_resize();
});
}
$.fn.viewimageresize2 = function (selector) {
var cfg = {
selector: "img"
};
if (typeof selector == "object") {
cfg = $.extend(cfg, selector);
} else {
if (selector) {
cfg = $.extend({ selector: selector });
}
}
2022-09-17 20:50:50 +09:00
var $img = this.find(cfg.selector);
var $this = this;
2022-09-17 20:50:50 +09:00
function image_resize() {
var width = $this.width();
2022-09-17 20:50:50 +09:00
$img.each(function () {
$(this).removeAttr("width")
.removeAttr("height")
.css("width", "")
.css("height", "");
2022-09-17 20:50:50 +09:00
if ($(this).data("width") == undefined)
$(this).data("width", $(this).width());
2022-09-17 20:50:50 +09:00
if ($(this).data("width") > width) {
$(this).css("width", "100%");
2022-09-17 20:50:50 +09:00
}
});
}
2022-09-17 20:50:50 +09:00
$(window).on("resize", function () {
image_resize();
});
2022-09-17 20:50:50 +09:00
image_resize();
}
}(jQuery));