html5 模仿苹果桌面,JavaScript模仿桌面窗口

这个大概花了YQ一天多时间(虽然含杂大量酱油时间),第一次做,惊现各种debug。网上说的果然没错——debug的时间比写程序的时间多……明显是因为自己没有在敲代码之前做好准备,忽略了很多细节,引以为戒。废话少说,以下是这次自学的笔记:?( ̄? ̄)?

添加了双击缩小放大窗口 & 改变窗口大小的预览效果

[博客文章网址,可运行代码查看效果] == > ver = function() {

201

if(bMousedowning) return false;

202

changeCursor(true, this.index);

203

};

204

boxSide[i].onmouseout = function() {

205

if(bMousedowning) return false;

206

changeCursor(false, this.index);

207

};

208

boxSide[i].onmousedown = function(event) {

209

var event = event || window.event;

210

var index = this.index;

211

var aBoxPrevious = new Array();         //记录box上一次的状态

212

aBoxPrevious["clientX"] = event.clientX;

213

aBoxPrevious["clientY"] = event.clientY;

214

aBoxPrevious["left"] = box.offsetLeft;

215

aBoxPrevious["top"]= box.offsetTop;

216

aBoxPrevious["width"] = box.offsetWidth;

217

aBoxPrevious["height"] = box.offsetHeight;

218

bMousedowning = true;

219

bSizeChanging = true;

220

showVirtualBox(virtualBox, aBoxPrevious);

221

document.onmousemove = function(event) {

222

if(!bSizeChanging) return false;

223

changeVirtualBoxSize(event, aBoxPrevious, index);

224

};

225

document.onmouseup = function() {

226

changeBoxSize(virtualBox)

227

hideVirtualBox(virtualBox);

228

bSizeChanging = false;

229

bMousedowning = false;

230

changeCursor(false, index);

231

};

232

return false;

233

};

234

}

235

//改变鼠标指针样式

236

var changeCursor = function(bIsShowing, index) {

237

if(bIsShowing) {

238

var cursorStyle = ["n-resize","e-resize","s-resize","w-resize","ne-resize","se-resize","sw-resize","nw-resize"];

239

document.body.style.cursor = cursorStyle[index];

240

}

241

else {

242

document.body.style.cursor = "";

243

}

244

};

245

//显示预览DIV

246

var showVirtualBox = function(virtualBox, aBoxPrevious) {

247

with(virtualBox.style) {

248

display = "block";

249

top = aBoxPrevious["top"] + "px";

250

left = aBoxPrevious["left"] + "px";

251

width = aBoxPrevious["width"] + "px";

252

height = aBoxPrevious["height"] + "px";

253

}

254

}

255

//隐藏预览DIV

256

var hideVirtualBox = function(virtualBox) {

257

virtualBox.style.display = "none";

258

}

259

//改变box大小

260

var changeVirtualBoxSize = function(event, aBoxPrevious, index) {

261

var event = event || window.event;

262

var bTop = bRight = bBottom = bLeft = false;

263

//八个方向,分别为N、E、S、W、NE、SW、SW、NW

264

switch (index) {

265

case 0:

266

bTop = true;

267

break;

268

case 1:

269

bRight = true;

270

break;

271

case 2:

272

bBottom = true;

273

break;

274

case 3:

275

bLeft = true;

276

break;

277

case 4:

278

bTop = bRight = true;;

279

break;

280

case 5:

281

bRight = bBottom = true;

282

break;

283

case 6:

284

bBottom = bLeft = true;

285

break;

286

case 7:

287

bLeft = bTop = true;

288

break;

289

default:

290

break;

291

}

292

//向北改变高度

293

if(bTop) {

294

var newTopHeight = aBoxPrevious["height"] - (event.clientY - aBoxPrevious["clientY"]);

295

(newTopHeight < originalHeight) && (newTopHeight = originalHeight);

296

(newTopHeight > aBoxPrevious["top"] + aBoxPrevious["height"]) && (newTopHeight = aBoxPrevious["top"] + aBoxPrevious["height"]);

297

var newTop = aBoxPrevious["top"] + (event.clientY - aBoxPrevious["clientY"]);

298

(newTop > aBoxPrevious["top"] + aBoxPrevious["height"] - originalHeight) && (newTop = aBoxPrevious["top"] + aBoxPrevious["height"] - originalHeight);

299

(newTop < 0) && (newTop = 0);

300

virtualBox.style.top = newTop + "px";

301

virtualBox.style.height = newTopHeight - box.clientTop * 2 + "px";      //不能忽略border-width

302

bTop = false;

303

}

304

//向东改变宽度

305

if(bRight) {

306

var newRightWidth = aBoxPrevious["width"] + (event.clientX - aBoxPrevious["clientX"]);

307

(newRightWidth < originalWidth) && (newRightWidth = originalWidth);

308

(newRightWidth > document.body.scrollWidth - aBoxPrevious["left"]) && (newRightWidth = document.body.scrollWidth - aBoxPrevious["left"]);

309

virtualBox.style.width = newRightWidth - box.clientTop * 2 + "px";

310

bRight = false;

311

}

312

//向南改变高度

313

if(bBottom) {

314

var newBottomHeight = aBoxPrevious["height"] + (event.clientY - aBoxPrevious["clientY"]);

315

(newBottomHeight < originalHeight) && (newBottomHeight = originalHeight);

316

(newBottomHeight > document.body.scrollHeight - aBoxPrevious["top"]) && (newBottomHeight = document.body.scrollHeight - aBoxPrevious["top"]);

317

virtualBox.style.height = newBottomHeight  - box.clientTop * 2 + "px";

318

bBottom = false;

319

}

320

//向西改变宽度

321

if(bLeft) {

322

var newLeftWidth = aBoxPrevious["width"] - (event.clientX - aBoxPrevious["clientX"]);

323

(newLeftWidth < originalWidth) && (newLeftWidth = originalWidth);

324

(newLeftWidth > aBoxPrevious["left"] + aBoxPrevious["width"]) && (newLeftWidth = aBoxPrevious["left"] + aBoxPrevious["width"]);

325

var newLeft = aBoxPrevious["left"] + (event.clientX - aBoxPrevious["clientX"]);

326

(newLeft > aBoxPrevious["left"] + aBoxPrevious["width"] - originalWidth) && (newLeft = aBoxPrevious["left"] + aBoxPrevious["width"] - originalWidth);

327

(newLeft < 0) && (newLeft = 0);

328

virtualBox.style.left = newLeft + "px";

329

virtualBox.style.width = newLeftWidth - box.clientLeft * 2 + "px";

330

bLeft = false;

331

}

332

};

333

var changeBoxSize = function(virtualBox) {

334

with(box.style) {

335

left = virtualBox.style.left;

336

top = virtualBox.style.top;

337

width = virtualBox.style.width;

338

height = virtualBox.style.height;

339

}

340

}

341

};

342

//窗口按钮函数

343

boxButton = function() {

344

var box = document.getElementById("box");

345

var boxHeader = document.getElementById("boxHeader");

346

var aButton = document.getElementById("button").getElementsByTagName("div");

347

var showButton = document.getElementById("showButton");

348

var span = showButton.getElementsByTagName("span")[0];

349

var bIsMin = bIsMax = false;        //目前状态是否最小 or 最大

350

boxHeader.ondblclick = function() {

351

maximize();

352

}

353

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

354

aButton[i].index = i;

355

aButton[i].onmouseover = function() {

356

aButton[this.index].style.background = "#AAA";

357

document.body.style.cursor = "pointer";

358

};

359

aButton[i].onmouseout = function() {

360

aButton[this.index].style.background = "";

361

document.body.style.cursor = ""

362

};

363

aButton[i].onclick = function() {

364

switch(this.index) {

365

case 0:

366

minimize();

367

break;

368

case 1:

369

maximize();

370

break;

371

case 2:

372

close();

373

break;

374

default:

375

break;

376

}

377

};

378

}

379

var minimize = function() {

380

if(bIsMin) {

381

resumeBox();

382

bIsMin = false;

383

}

384

else {

385

box.style.width = "89px";

386

box.style.height = "32px";

387

box.style.left = "2%";

388

box.style.top = box.style.top = document.body.offsetHeight - box.offsetHeight - 15 + "px";

389

bIsMin = true;

390

bIsMax = false;

391

}

392

};

393

var maximize = function() {

394

if(bIsMax) {

395

resumeBox();

396

bIsMax = false;

397

}

398

else {

399

box.style.width = document.body.scrollWidth - 10 + "px";

400

box.style.height = document.body.scrollHeight - 10 + "px";

401

box.style.left = "5px";

402

box.style.top = "5px";

403

bIsMax = true;

404

bIsMin = false;

405

}

406

};

407

var close = function() {

408

box.style.display = "none";

409

showButton.style.display = "block";

410

};

411

var resumeBox = function() {

412

box.style.top = "30%";

413

box.style.left = "40%";

414

box.style.width = "250px";

415

box.style.height = "150px";

416

};

417

showButton.onmousedown = function() {

418

span.innerHTML = "^o^";

419

};

420

showButton.onclick = function() {

421

this.style.display = "none";

422

span.innerHTML = ">_423

resumeBox();

424

box.style.display = "block";

425

};

426

};

427

window.onload = function() {

428

changeSize();

429

dragDiv();

430

boxButton();

431

};

432

《script》

433

434

435

436

437

438

439

440

441

442

443

444

445

446

447

448

449

450

451

452

453

454

>_<

居然关掉人家,讨厌~

快打开

455

456

457

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
H5即HTML5是一种用于网页设计和开发的标准技术,具有跨平台、跨浏览器的特点。苹果app下载页面通常采用简洁、美观的设计风格,因此可以使用H5来模仿苹果app下载页面模板。 首先,可以选择一款适合的H5模板,该模板应该包含苹果app下载页面所需的元素和功能,如应用的名称、图标、简介、截图等。可以通过自定义选项来修改模板的样式、颜色和布局,使之符合苹果app下载页面的风格。 其次,我们可以使用HTML5和CSS3来创建所需的布局和界面。通过HTML5的语义化标签,将页面内容结构化,并使用CSS3来设置样式和布局。可以运用Flexbox或网格布局等技术来实现页面的自适应和响应式设计,确保在不同的设备和屏幕上都能良好地显示。 另外,可以使用JavaScript来实现一些交互功能,例如点击下载按钮后的提示弹窗、应用评分和评论等。可以使用jQuery或其他JavaScript库来简化开发过程,并使用AJAX技术来进行数据的动态加载和更新。 最后,需要进行页面的优化和调试,确保页面的加载速度和性能。可以压缩和合并CSS和JavaScript文件,使用图片压缩和懒加载等技术来减少页面的加载时间。同时,还需要进行兼容性测试,确保页面在主流浏览器和移动设备上的正常运行。 总之,通过使用H5技术和合适的模板,可以很好地模仿苹果app下载页面。通过HTML5、CSS3和JavaScript的组合运用,可以实现页面的设计、布局、交互和优化等要求,使得模仿的页面具有良好的用户体验和视觉效果。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值