小编uni*_*ers的帖子

我的jQuery代码正在运行,但从程序员的角度来看它是非常糟糕的吗?

我拼凑了这个jQuery函数.它的目的是计算内部所有img元素的边距,div.article以便平衡图像的高度与文档的基线网格,为20像素.为了匹配我的基线网格,每个图像高度应为20的倍数.如果不是这种情况,例如一个图像的高度为154像素,则该函数会为img添加6 px的余量,以便与基线平衡网格已恢复.

该函数正常工作,所以我的实际问题是:由于我不是程序员,我想知道我的代码是否非常糟糕,虽然它正在工作,如果是这样,代码如何改进?

jQuery代码:

$('div.article img').each(function() {

    // define line height of CSS baseline grid:
    var line_height = 20;

    // capture the height of the img:
    var img_height = $(this).attr('height');

    // divide img height by line height and round up to get the next integer:
    var img_multiply = Math.ceil(img_height / line_height);

    // calculate the img margin needed to balance the height with the baseline grid:
    var img_margin = (img_multiply * line_height) - img_height;

    // if …
Run Code Online (Sandbox Code Playgroud)

javascript jquery vertical-rhythm

3
推荐指数
1
解决办法
346
查看次数

PHP:如何提供正确的内容类型(取决于文件扩展名?)?

我正在使用下面的脚本来gzip一些CSS和JS文件.它工作得很好 - 除了提供错误内容类型的JS文件(而不是相应的应用程序/ x-javascript).我如何改进PHP代码以提供正确的内容类型?谢谢!

的.htaccess:

AddHandler application/x-httpd-php .css .js
php_value auto_prepend_file gzip.php
Run Code Online (Sandbox Code Playgroud)

gzip.php:

<?php 
ob_start ("ob_gzhandler");
header("Content-type: text/css; charset: UTF-8");
header("Cache-Control: must-revalidate");
$offset = 60 * 60 ;
$ExpStr = "Expires: " . 
gmdate("D, d M Y H:i:s",
time() + $offset) . " GMT";
header($ExpStr);
?>
Run Code Online (Sandbox Code Playgroud)

javascript php .htaccess gzip content-type

0
推荐指数
1
解决办法
1359
查看次数