在线html 布局编辑,HTML5 可在线编辑的多列布局图文页面

本文介绍了一个使用JavaScript实现的动态内容生成系统。该系统通过调用外部API获取文本内容,并利用jQuery操作DOM来更新页面样式及内容。此外,还实现了触摸事件监听,增强了移动端用户体验。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

JavaScript

语言:

JaveScriptBabelCoffeeScript

确定

$(function() {

getBaconIpsum()

$(".panel").on("change touchend touchstart", setValues);

setValues();

});

function setValues() {

var css = "";

$(".updater").each(function() {

var $this = $(this);

var property = $this.data("change");

if (typeof property !== "undefined") {

var unit = $("." + property + "-unit").val() || "";

var prop = PrefixFree.prefixProperty(property);

if (this.value != unit) {

var val = this.value + unit;

css += "" + prop + ": " + val + ";";

$(".output").css(prop, val);

}

}

});

$(".css").html(css);

}

function getBaconIpsum() {

$.getJSON('http://baconipsum.com/api/?callback=?', {

'type': ((Math.random() > .5) ? 'meat-and-filler' : 'all-meat'),

'start-with-lorem': '1',

'paras': '15'

},

function(baconGoodness) {

if (baconGoodness && baconGoodness.length > 0) {

$(".output").html('');

for (var i = 0; i < baconGoodness.length; i++) {

var sHeader = "";

if (Math.random() > .4 || i === 0) {

var htype = parseInt(Math.random() * 4) + 1;

var header = baconGoodness[i].split(" ");

var noOfWords = parseInt(Math.random() * 10) + 2;

var wStart = parseInt(Math.random() * (header.length - noOfWords));

sHeader = "";

for (var ii = wStart; ii < wStart + noOfWords; ii++) {

sHeader += header[ii].replace(/[\.,]/ig, "") + " ";

};

sHeader += "";

}

var text = baconGoodness[i].split(" ");

text = addImage(text).join(" ");

$(".output").append(sHeader + '

' + text + '

');

}

}

});

}

function addImage(arr) {

var width = parseInt(Math.random() * 6) * 40 + 80;

var height = parseInt(Math.random() * 6) * 40 + 40;

var sSrc = "sports";

arr.splice(Math.random() * arr.length, 0, sSrc);

return arr;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值