延迟加载不适用于光滑轮播中的响应式图像

时间:2016-06-24 11:54:40

标签: javascript html lazy-loading slick.js responsive-images

我在 do.call(rbind, lst) 中延迟加载图片时遇到问题。当我使用屏幕低于980px的设备时,一切正常(按需加载较小的图像)。但是当我在分辨率大于980px的屏幕上时,它会加载所有大图像,而不是按需加载小图像。

.cshtml文件

slick carousel

.js文件

@{
    Javascript.Includes.Add("views/home/home-ads-carousel.js");
    Javascript.Code.Add("views.home.carousel.init();");
}

        <div class="ad_carousel">
            @foreach (var ad in homepageAds)
            {
                <div class="post__image-container">
                    <picture>
                        <source media="(min-width: 980px)" srcset="@(Configuration.URLs.MediaPath + ad.ImagePath)" />
                        <img class="post__featured-image" data-lazy="@(Configuration.URLs.MediaPath + ad.SmallImagePath)" />
                    </picture>
                    <div class="carousel_text">
                        <h2>@ad.Title</h2>
                        <p>@ad.CallToActionText</p>
                    </div>
                </div>
            }                           
        </div>
提前谢谢。

1 个答案:

答案 0 :(得分:0)

你能试试吗

Sub OrganizeTable()

Dim TableArray()                        As Variant
Dim i, j, k, i_tmp, LastRow             As Long
Dim Sum_Count                           As Integer
Dim SheetData, SheetResult              As Excel.Worksheet
Dim StringTemp                          As String
Dim LongMin, LongMax                    As Long
Dim SumExpense()                        As Long
Dim Number_of_ID                        As Long
Dim Number_of_Expense_Type              As Integer

' Number_of_Expense_Type = number of expense type you have in your
Number_of_Expense_Type = InputBox("Enter number of expense type ", "Expense Type counter")

Set SheetData = ActiveWorkbook.Worksheets("Sheet1")
LastRow = SheetData.Cells(SheetData.Rows.Count, "A").End(xlUp).row
Set SheetResult = ActiveWorkbook.Worksheets("Sheet2")
Erase TableArray

ReDim TableArray(1 To LastRow - 1, 1 To 3 + Number_of_Expense_Type) ' create array with exact number of Project names
ReDim SumExpense(1 To Number_of_Expense_Type)
i = 2
' insert all table's data into multi-dimensional array (easier and faster to manipulate later)
While SheetData.Cells(i, 1) <> ""
    For j = 1 To 3 + Number_of_Expense_Type
        TableArray(i - 1, j) = SheetData.Cells(i, j)
    Next
    i = i + 1
Wend


LongMin = LBound(TableArray())
LongMax = UBound(TableArray())

' this loop is for sorting the array according to Name, and then No. ID
For i = LongMin To LongMax - 1
    For j = i + 1 To LongMax
        ' 1st rule: check for Name Value in Column A
        If TableArray(i, 1) > TableArray(j, 1) Then
            For k = 1 To 3 + Number_of_Expense_Type
                StringTemp = TableArray(i, k)
                TableArray(i, k) = TableArray(j, k)
                TableArray(j, k) = StringTemp
            Next
        End If
        ' 2nd rule: check for No. ID in Column c
        If TableArray(i, 1) = TableArray(j, 1) And TableArray(i, 3) > TableArray(j, 3) Then
            For k = 1 To 3 + Number_of_Expense_Type
                StringTemp = TableArray(i, k)
                TableArray(i, k) = TableArray(j, k)
                TableArray(j, k) = StringTemp
            Next
        End If

    Next
Next


i = 1
j = 2 ' this is the Row number where the sorted table will start
k = 1 ' this is the Column number where the sorted table will start
While i <= LongMax
    SheetResult.Cells(j, k) = TableArray(i, 1)
    SheetResult.Cells(j, k + 1) = TableArray(i, 2)
    SheetResult.Cells(j, k + 2) = TableArray(i, 3)

    For Sum_Count = 1 To Number_of_Expense_Type
        SumExpense(Sum_Count) = TableArray(i, 4 + Sum_Count - 1)
    Next

    ' this IF and WHILE loop are for accumulating the Sum Expense 1 and Sum Expense 2 for the same ID type
    If i + 1 <= LongMax Then
        While TableArray(i, 3) = TableArray(i + 1, 3) And TableArray(i, 1) = TableArray(i + 1, 1)

            For Sum_Count = 1 To Number_of_Expense_Type
                SumExpense(Sum_Count) = SumExpense(Sum_Count) + Val(TableArray(i + 1, 4 + Sum_Count - 1))
            Next

            i = i + 1
        Wend
    End If

    ' this IF and WHILE loop are for counting how many Num of ID you have per Name
    Number_of_ID = 0
    If TableArray(i, 3) <> "-" Then
        Number_of_ID = 1
        For i_tmp = 1 To LongMax - 1
            While Cells(j, k) = TableArray(i_tmp + 1, 1) And TableArray(i_tmp, 1) = TableArray(i_tmp + 1, 1) And TableArray(i_tmp, 3) <> TableArray(i_tmp + 1, 3)
                Number_of_ID = Number_of_ID + 1
                i_tmp = i_tmp + 1
            Wend
        Next
    Else
        Number_of_ID = 0
    End If

    SheetResult.Cells(j, k + 3) = Number_of_ID

    For Sum_Count = 1 To Number_of_Expense_Type
        SheetResult.Cells(j, k + 4 + Sum_Count - 1) = SumExpense(Sum_Count)
        SumExpense(Sum_Count) = 0
    Next

    Number_of_ID = 0
    j = j + 1
    i = i + 1
Wend

' writing down the headers for you table
SheetResult.Cells(1, k) = "Name"
SheetResult.Cells(1, k + 1) = "Entry"
SheetResult.Cells(1, k + 2) = "No. ID"
SheetResult.Cells(1, k + 3) = "Number of ID"

For Sum_Count = 1 To Number_of_Expense_Type
    SheetResult.Cells(1, k + 4 + Sum_Count - 1) = "Sum of Expense " & Sum_Count
Next

Set SheetData = Nothing
Set SheetResult = Nothing

End Sub

而不是

public class MyEntity {
    public DateTime LocalDateTime {get; set;}

    //use this property in code instead of LocalDateTime.
    [NoMapped]
    public DateTime UtcDateTime {
        get { return /*convert LocalDateTime value to UTC */ }
        set { LocalDateTime = /*convert value to local zone */ }
    }
}

这应该有效!