我正在尝试使用此脚本将HTML从A点移动到移动设备上的B点(767px及以下)。但它似乎不起作用。我已经通过ID和innerHTML选择了元素,但我似乎没有运气。
var addEvent = function(object, type, callback) {
if (object == null || typeof(object) == 'undefined') return;
if (object.addEventListener) {
object.addEventListener(type, callback, false);
} else if (object.attachEvent) {
object.attachEvent("on" + type, callback);
} else {
object["on"+type] = callback;
}
};
var element;
element = document.getElementById('pointA');
recalcHTML();
addEvent(window, "resize", recalcHTML());
function recalcHTML() {
var element = element;
var target = document.getElementById('pointB');
if (window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth <= 767) {
target.appendChild(element);
} else {
element.appendChild(target);
}
}
HTML:
<div id="pointA"><img src="/images/example.jpg" alt="" width="300" /></div>
<div id="pointB"></div>