javascript - 打印时不要使用 jQuery DOM 更改

标签 javascript css dom printing fullpage.js

更新:下面的 CSS 解决方案。

我正在使用 fullpage.js不幸的是,jQuery 插件也会影响网页的打印,只显示当前视口(viewport)显示及其兄弟。

我遇到的问题是打印命令使用 DOM(很明显),但插件已经在 DOM 中进行了内联 CSS 更改。有没有办法禁用 print 的 DOM 更改?

这行不通,但这是我的想法:

$(document).ready(function() {
    if(@media !print) { // PS: Not real code!
        $('#fullpage').fullpage();
    }
});

------ CSS解决方案------

Praveen's reply引导我走上正确的道路。覆盖 fullpage.js 内联样式所需的 CSS 是:

/* Override javascript inline styles */
html,
body {
    overflow: visible !important;
    height: auto !important;
}

.fullpage-wrapper {
    height: auto !important;
    transform: none !important;
    transition: none !important;
}

.fp-section {
    height: auto !important;
}

.fp-slidesContainer {
    width: auto !important;
    transition: none !important;
    transform: none !important;
}

.fp-slides,
.fp-slides * {
    position: static !important;
}

.fp-slide {
    width: auto !important;
}

最佳答案

在你的 CSS 中做这样的事情:

隐藏整页幻灯片:

.fp-slides {
  display: none;
}

或者使它们成为静态的,因为这将通过正常呈现内容来完成这些工作:

.fp-slides, .fp-slides * {
  position: static !important;
  /* I don't like putting !important,
     but there is no other way to override the inline styles without this!*/
}

否则,您可以指定样式表仅适用于screen作为媒体:

<link rel="stylesheet" href="fullpage.css" media="screen" />

关于javascript - 打印时不要使用 jQuery DOM 更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32045139/

相关文章:

html - 这是覆盖 div 元素的正确方法吗?

jquery - 从 TAB 跳转中跳过焦点

JavaScript 和 IE 错误 HIERARCHY_REQUEST_ERR (3)

javascript - 如何为此 p5 Javascript 草图创建工作菜单屏幕?

html - 媒体查询不起作用(提供代码)

javascript - 如何正确创建一个textNode并附加到特定位置?

javascript - Angular Js - 操作 DOM 并添加点击行为

JavaScript Gallery 故障(图层??)

javascript - 如何从表单中的表中删除最后一行,而没有插入数据的其他行?

javascript - Chrome,FileReader API,event.target.result === ""